/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author XuanTuan
 */
public class User {

    String username;
    String pass;

    public static boolean saveUser(String username, String pass, String sex, String email) {
        boolean result = false;
        Connection con = ConnectDatabase.getConnection();
        try {
            Statement state = con.createStatement();
            String sql = "insert into user(username,password,sex,email) values('"
                    + username + "','" + pass + "','" + sex + "','" + email + "')";
            int number = state.executeUpdate(sql);
            if (number > 0) {
                result = true;
            }
            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return result;
    }

    public static boolean login(String username, String pass) {
        boolean result = false;
        Connection con = ConnectDatabase.getConnection();
        try {
            System.out.println("sssssssssssssssssss");
            Statement state = con.createStatement();
            String sql = "SELECT * FROM `user` WHERE username = '" + username + "' AND `password` = '" + pass + "'";
            ResultSet resultSet = state.executeQuery(sql);
            while (resultSet.next()) {
                System.out.println("asagawfawfwafwafa");
                result = true;
            }
            System.out.println(result);
            con.close();
        } catch (SQLException ex) {
            System.out.println("vvvvvvvvvvvvvvvvvv");
            ex.printStackTrace();
        }
        return result;
    }
}
